package com.liyu.iblog.utils;


public class StringUtils {
    
    public static String transformToHyphenSeparatedString(String str) {
        String temp = str.trim();
        return temp.replaceAll("\\s+", "-").toLowerCase();
    }

    /**
     * TODO: define some convention of blog content
     * @param content
     * @return
     */
    public static String makeSummary(String content) {
        //extract the first paragraph of the blog content
        int pStartTagIndex = content.indexOf("<p>");
        if (pStartTagIndex >= 0) {
            int pEndTagIndex = content.indexOf("</p>");
            int pEndClosingTagIndex = content.indexOf('>', pEndTagIndex);
            return content.substring(pStartTagIndex, pEndClosingTagIndex + 1);
        } else {
            //if doesn't contains paragraph get some code as summary
            int preStartTagIndex = content.indexOf("<pre");
            if (preStartTagIndex >= 0) {
//                int preStartTagIndexClosing = content.indexOf('>', preStartTagIndex);
                int preEndTagIndex = content.indexOf("</pre>");
                return content.substring(preStartTagIndex, preEndTagIndex);
            } else {
                return null;
            }
        }
        
    }
    
}
